package com.group.eams.service.impl;

import com.group.eams.entity.Employee;
import com.group.eams.mapper.EmployeeMapper;
import com.group.eams.service.IEmployeeService;
import com.group.eams.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by zcy-fover on 2016/10/31.
 */
@Service
public class EmployeeServiceImpl implements IEmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    /**
     * @param account
     * @param password
     * @return
     */
    @Override
    public Employee findEmployeeByAccount(String account, String password) {
        return employeeMapper.findEmployeeByAccount(account);
    }

    /**
     * 获取员工列表
     *
     * @return
     */
    @Override
    public List<Employee> getEmployeeList() {
        return employeeMapper.getAllEmployee();
    }

    /**
     * 通过员工id查询员工
     *
     * @param id
     * @return
     */
    @Override
    public Employee findEmployeeById(int id) {
        return employeeMapper.findEmployeeById(id);
    }

    /**
     * 添加员工
     *
     * @param employee
     * @return
     */
    @Override
    public Result addEmployee(Employee employee) {
        Result result = new Result();
        if (employeeMapper.addEmployee(employee)){
            result.setSuccess(true);
            result.setMessage("添加成功");
            return result;
        } else {
            result.setSuccess(false);
            result.setMessage("添加失败");
            return result;
        }
    }

    /**
     * 更新员工信息
     *
     * @param employee
     * @return
     */
    @Override
    public Result updateEmployee(Employee employee) {
        Result result = new Result();
        if (employeeMapper.updateEmployee(employee)){
            result.setSuccess(true);
            result.setMessage("更新成功");
            return result;
        } else {
            result.setSuccess(false);
            result.setMessage("更新失败");
            return result;
        }
    }

    /**
     * 通过员工id删除员工
     *
     * @param id
     * @return
     */
    @Override
    public Result deleteEmployeeById(int id) {
        Result result = new Result();
        if (employeeMapper.deleteEmployeeById(id)){
            result.setSuccess(true);
            result.setMessage("删除成功");
            return result;
        } else {
            result.setSuccess(false);
            result.setMessage("删除失败");
            return result;
        }
    }

    /**
     * 根据姓名查找
     *
     * @param name 姓名
     * @return 返回集
     */
    @Override
    public List<Employee> getEmployeeByName(String name) {
        return employeeMapper.getEmployeeByName(name);
    }

    @Override
    public List<Employee> getEmployeeBySex(Integer sex) {
        return null;
    }
}
